package middleware

import (
	"context"

	"github.com/nsqio/go-nsq"

	"bilinadmin/pkg/mq"
)

// MqErrHandler nsq 错误处理
func MqErrHandler(handler mq.MqHandlerFunc) mq.MqHandlerFunc {
	return func(ctx context.Context, msg *nsq.Message) error {
		err := handler(ctx, msg)
		if err != nil {
			sendMail(ctx, err, "MQ")
		}
		return err
	}
}
